<template>
  <div class="">

    
  <Form :model="EmbryoMoveDetail" label-position="left" :label-width="50">
          

          <Form-item label="胚胎性别">
              <Input v-model="EmbryoMoveDetail.gender"></Input>
          </Form-item>
           <Form-item label="胚胎个数">
              <Input v-model="EmbryoMoveDetail.number"></Input>
          </Form-item>
      
      
          

          <Form-item label="胚胎等级">
              <Input v-model="EmbryoMoveDetail.grade"></Input>
          </Form-item>


          <Form-item label="移植时间">
              <Date-picker style="float:left" type="date" placeholder="请选择移植时间" v-model="EmbryoMoveDetail.date"></Date-picker>
           </Form-item>

           <upload-helper 
              @handleSuccess="handleSuccess"
             v-bind:defaultList="EmbryoMoveDetail.innerlist" 
             LeftTitle="移植前检查报告" 
             v-bind:selectType="bodyType">
           </upload-helper>
          

      </Form>




  </div>
</template>
<script>
import api from '../js/axios-module'
import UploadHelper from '../components/UploadHelper'
export default {

  data () {
    return {
       EmbryoMoveDetail:{
          id:'',
          embryoid:'',
          gender:"",
          grade:'',
          number:'',
          date:new Date(),
          dateStr:'',
          innerlist:[ ],
       },
       bodyType:""
    }
  },methods:{
    handleSuccess:function(res,flie,selectType,type){


      this.EmbryoMoveDetail.innerlist.push({
          'name': flie.url,
          'url': flie.url,
          'created_at':flie.created_at
      })
    },
    openItem:function(number){
        

      if (number !=-1) {
        console.log("openItem:修改")
        //get
        let item = this.EmbryoMove.data[number];
        this.EmbryoMoveDetail.id = item.id
        this.EmbryoMoveDetail.gender= item.gender  
        this.EmbryoMoveDetail.grade =item.grade
        this.EmbryoMoveDetail.number  = item.number 
        this.EmbryoMoveDetail.date  = item.date
        this.EmbryoMoveDetail.innerlist  = item.innerlist




      }else{
        
         console.log("openItem:新增")
          this.EmbryoMoveDetail.gender = ""
          this.EmbryoMoveDetail.grade = ""
          this.EmbryoMoveDetail.number = ""
          this.EmbryoMoveDetail.date = new Date()
          this.EmbryoMoveDetail.innerlist = []
      }
    },
    updateItem:function(number){
      
      if (number !=-1) {
        //set
        console.log("updateItem:修改")
        // 发送网络请求 
        var item = new Object();
        item.embryoid = this.EmbryoMoveDetail.id
        item.data = {}
        if (this.EmbryoMoveDetail.date instanceof Date) {

            item.data.date = this.EmbryoMoveDetail.date.format("yyyy-MM-dd");
        }else{
            item.data.date = this.EmbryoMoveDetail.date
        }
 
        item.data.embryosex = this.EmbryoMoveDetail.gender,
        item.data.embryograde= this.EmbryoMoveDetail.grade,
        item.data.embryonumber= this.EmbryoMoveDetail.number
        item.file = this.EmbryoMoveDetail.innerlist


        api.editEmbrosMove(item).then(respones=>{
   
            if(respones.data.code=200){
              this.$Message.success("修改成功")
              var cell = this.EmbryoMove.data[number];
              cell.date = item.data.date
              cell.gender = this.EmbryoMoveDetail.gender
              cell.grade = this.EmbryoMoveDetail.grade
              cell.number = this.EmbryoMoveDetail.number

            }
        },err=>{
            console.log(err)
        })

        //动态更新本地数据



   
      }else{
        //新增
        console.log("updateItem:新增")

         var item = new Object();
        item.embryoid = this.EmbryoMoveDetail.id
        item.data = {}
        if (this.EmbryoMoveDetail.date instanceof Date) {
            item.data.date = this.EmbryoMoveDetail.date.format("yyyy-MM-dd");
        }else{
            item.data.date = this.EmbryoMoveDetail.date
        }
 
        item.data.embryosex = this.EmbryoMoveDetail.gender,
        item.data.embryograde= this.EmbryoMoveDetail.grade,
        item.data.embryonumber= this.EmbryoMoveDetail.number
        item.file = this.EmbryoMoveDetail.innerlist
        api.setEmbrosMove(item).then(respones=>{
       
            if(respones.data.code=200){
              this.$Message.success("新增成功")

                  //成功后添加到数据中
              this.EmbryoMove.data.push({
                "id":respones.data.id,
                "date":this.EmbryoMoveDetail.date.format("yyyy-MM-dd"),
                "gender":this.EmbryoMoveDetail.gender,
                "grade":this.EmbryoMoveDetail.grade,
                "number":this.EmbryoMoveDetail.number,
                "innerlist":this.EmbryoMoveDetail.innerlist,
              });
              
            }
        },err=>{
            console.log(err)
        })


        




      }
    }
  },
  components:{UploadHelper},
  props:['EmbryoMove'],
  watch:{
    'EmbryoMoveDetail':{
      handler:function(val,oldval){
  
      },
      deep:true
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>   /*  scoped的意思是这里的样式只对当前页面有效不会影响其他页面，还有可以设置lang="scss"就是支持css预编译，也就是支持sass或者less  */

</style>
